<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改仪器设备')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-list-edit" th:object="${instrumentList}">
            <h4 class="form-header h4">仪器设备信息</h4>
            <input name="instrumentId" th:field="*{instrumentId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">仪器名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">型号规格：</label>
                <div class="col-sm-8">
                    <input name="specification" th:field="*{specification}" class="form-control" type="text">
                </div>
            </div>
            <input name="deptId" type="hidden" id="treeId" th:field="*{department}"/>
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属部门：</label>
                <div class="col-sm-8">
<!--                    <input name="department" th:field="*{department}" class="form-control" type="text">-->
                    <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="默认当前部门" class="form-control">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">主要技术指标：</label>
                <div class="col-sm-8">
                    <input name="indicator" th:field="*{indicator}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">检定有效期(单位：天)：</label>
                <div class="col-sm-8">
                    <input name="validTime" th:field="*{validTime}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">存放位置：</label>
                <div class="col-sm-8">
<!--                    <input name="saveLocation" th:field="*{saveLocation}" class="form-control" type="text">-->
                    <select name="saveLocation" class="form-control" >
                        <option th:value="*{saveLocation}" th:field="*{saveLocation}"><span th:text="${name.wareName}"></span></option>
                        <option th:each="item,info:${wareHouse}"th:object="${item}" th:value="*{id}"><span th:text="*{name}"></span></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">创建人：</label>
                <div class="col-sm-8">
<!--                    <input name="creater" th:field="*{creater}" class="form-control" type="text">-->
                    <input name="creater" class="form-control" th:value="${user.userId}"  type="hidden">
                    <span th:text="${user.userName}"></span>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">创建时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="createdTime" th:value="${#dates.format(instrumentList.createdTime, 'yyyy-MM-dd')}" disabled class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否出库：</label>
                <div class="col-sm-8">
<!--                    <input name="instrumentOut" th:field="*{instrumentOut}" class="form-control" type="text">-->
                    <select name="instrumentOut" class="form-control" type="text">
                        <option th:value="*{instrumentOut}"   th:field="*{instrumentOut}"><span th:text="*{instrumentOut}"></span></option>
                        <option value="已出库">已出库</option>
                        <option value="未出库">未出库</option>
                    </select>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/list";
        $("#form-list-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-list-edit').serialize());
            }
        }

        $("input[name='createdTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        /* 用户管理-新增-选择部门树 */
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/user/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            console.log(deptId)
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }
        $(function() {
            var options = {
                data: [[${instrumentList.sysWarehouseList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'name',
                    align: 'center',
                    title: '库房名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].name' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'line',
                    align: 'center',
                    title: '规格',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].line' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'type',
                    align: 'center',
                    title: '类型',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].type' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'createName',
                    align: 'center',
                    title: '创建人',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].createName' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'createTime',
                    align: 'center',
                    title: '创建时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].createTime' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'userState',
                    align: 'center',
                    title: '使用状态',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].userState' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'state',
                    align: 'center',
                    title: '状态',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysWarehouseList[%s].state' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                name: "",
                line: "",
                type: "",
                createName: "",
                createTime: "",
                userState: "",
                state: "",
            }
            sub.addRow(row);
        }
    </script>
</body>
</html>